package com.isoftstone.plugin.freemark;

import com.jagregory.shiro.freemarker.ShiroTags;
import freemarker.cache.TemplateLoader;
import freemarker.template.TemplateException;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;

import java.io.IOException;
import java.util.List;

/**
 * Created by dell on 2016/5/10.
 */
public class ShiroTagFreeMarkerConfigurer extends FreeMarkerConfigurer {
    @Override
    public void afterPropertiesSet() {
        try {
            super.afterPropertiesSet();
            this.getConfiguration().setSharedVariable("shiro", new ShiroTags());
            this.getConfiguration().setTemplateExceptionHandler(new FreemarkerExceptionHandler());
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        }

    }
    @Override
    protected TemplateLoader getAggregateTemplateLoader(List<TemplateLoader> templateLoaders) {

        return new HtmlTemplateLoader(super.getAggregateTemplateLoader(templateLoaders));

    }

}